<?php
//permissions_check.php
    function sql_permissions_check($t_array, $action='', $contrib='') {}
    function php_permissions_check($t_array, $action='', $contrib='') {}

    function make_dir_permissions_check($t_array, $action='', $contrib='') {
        if($t_array[0]) {
            for($loop_index = 0; $loop_index<count($t_array); $loop_index++) {
                    if(!is_writable(DIR_FS_CATALOG . $t_array[$loop_index]['PARENT_DIR']['@']['NAME'])) {
                        $permissions_needed.='(make_dir #'.($loop_index+1).') '.WRITE_PERMISSINS_NEEDED_TEXT.DIR_FS_CATALOG . $t_array[$loop_index]['PARENT_DIR']['@']['NAME']."<br>";
                    }
                if ($action=='remove') {
                   $directory = DIR_FS_CATALOG . $t_array[$loop_index]['PARENT_DIR']['@']['NAME'] . $t_array[$loop_index]['DIR']['@']['NAME'];
                    while (dirname(DIR_FS_CATALOG . $t_array[$loop_index]['PARENT_DIR']['@']['NAME']) != ($directory = dirname($directory))) {
                        if(!is_writable($directory))    $permissions_needed.='(make_dir #'.($loop_index+1).') '.WRITE_PERMISSINS_NEEDED_TEXT.$directory."<br>";
                    }
                }
            }
        }
        return $permissions_needed;
    }


    function findreplace_permissions_check($t_array, $action='', $contrib='') {
        if($t_array[0]) {
            for($loop_index = 0; $loop_index<count($t_array); $loop_index++) {
                if (!file_exists(DIR_FS_CATALOG . $t_array[$loop_index]['FILE'][0]['@']['NAME'])) {
                        return '(findreplace #'.($loop_index+1).') '.CANT_READ_FILE . DIR_FS_CATALOG . $t_array[$loop_index]['FILE'][0]['@']['NAME']."<br>";
                } elseif(!is_writable(DIR_FS_CATALOG . $t_array[$loop_index]['FILE'][0]['@']['NAME']))
                    return '(findreplace #'.($loop_index+1).') '.WRITE_PERMISSINS_NEEDED_TEXT. DIR_FS_CATALOG . $t_array[$loop_index]['FILE'][0]['@']['NAME']."<br>";
            }
        }
    }


    function addcode_permissions_check($t_array, $action='', $contrib='') {
        if ($t_array[0]) {
            for($loop_index = 0; $loop_index<count($t_array); $loop_index++) {
                if (!file_exists(DIR_FS_CATALOG . $t_array[$loop_index]['FILE'][0]['@']['NAME'])) {
                        return '(addcode #'.($loop_index+1).') '.CANT_READ_FILE . DIR_FS_CATALOG . $t_array[$loop_index]['FILE'][0]['@']['NAME']."<br>";
                } elseif(!is_writable(DIR_FS_CATALOG . $t_array[$loop_index]['FILE'][0]['@']['NAME']))
                    return '(addcode #'.($loop_index+1).') '.WRITE_PERMISSINS_NEEDED_TEXT. DIR_FS_CATALOG . $t_array[$loop_index]['FILE'][0]['@']['NAME']."<br>";
            }
        }
    }

    function del_file_permissions_check($t_array, $action='', $contrib='') {
        if ($t_array[0]) {
            if ($action=='install') {
                for($loop_index = 0; $loop_index<count($t_array); $loop_index++) {
                    if (file_exists(DIR_FS_CATALOG . $t_array[$loop_index]['FILE'][0]['@']['NAME'])) {
                        if(!is_writable(dirname(DIR_FS_CATALOG . $t_array[$loop_index]['FILE'][0]['@']['NAME']))) {
                            return '(del_file #'.($loop_index+1).') '.WRITE_PERMISSINS_NEEDED_TEXT.DIR_FS_CATALOG . $t_array[$loop_index]['FILE'][0]['@']['NAME']."/<br>";
                        }
/*
                        $error_path=recursive_permissions_check(DIR_FS_CATALOG . $t_array[$loop_index]['FILE'][0]['@']['NAME']);
                        if ($error_path)     return '(del_file #'.($loop_index+1).') '.WRITE_PERMISSINS_NEEDED_TEXT.$error_path."<br>";
*/
                    }
                }
            } elseif ($action=='remove') {
                for($loop_index = 0; $loop_index<count($t_array); $loop_index++) {
                    if (file_exists(DIR_FS_CATALOG . $t_array[$loop_index]['FILE'][0]['@']['NAME'])) {
                        if(!is_writable(dirname(DIR_FS_CATALOG . $t_array[$loop_index]['FILE'][0]['@']['NAME']))) {
                            return '(del_file #'.($loop_index+1).') '.WRITE_PERMISSINS_NEEDED_TEXT.DIR_FS_CATALOG . $t_array[$loop_index]['FILE'][0]['@']['NAME']."/<br>";
                        }
/*
                        $error_path=recursive_permissions_check(DIR_FS_CATALOG . $t_array[$loop_index]['FILE'][0]['@']['NAME']);
                        if ($error_path)     return '(del_file #'.($loop_index+1).') '.WRITE_PERMISSINS_NEEDED_TEXT.$error_path."<br>";
*/
                    }
                }
            }
        }
    }

    function addfile_permissions_check($t_array, $action='', $contrib='') {
        if ($t_array[0]) {
            if ($action=='install') {
                for($loop_index = 0; $loop_index<count($t_array); $loop_index++) {
                    if(!is_dir(dirname(DIR_FS_CATALOG . $t_array[$loop_index]['FILE'][0]['@']['NAME']))) {
                        recursive_mkdir(dirname(DIR_FS_CATALOG . $t_array[$loop_index]['FILE'][0]['@']['NAME']));
                        //recursive_chmod(dirname(DIR_FS_CATALOG . $t_array[$loop_index]['FILE'][0]['@']['NAME']), '511');
                    }
//                        $error_path=recursive_permissions_check(dirname(DIR_FS_CATALOG . $t_array[$loop_index]['FILE'][0]['@']['NAME']));
//                        if ($error_path)     return '(addfile #'.($loop_index+1).') '.WRITE_PERMISSINS_NEEDED_TEXT.$error_path."<br>";
                    if(!is_writable(dirname(DIR_FS_CATALOG . $t_array[$loop_index]['FILE'][0]['@']['NAME']))) {
                    return '(addfile #'.($loop_index+1).') '.WRITE_PERMISSINS_NEEDED_TEXT.dirname(DIR_FS_CATALOG . $t_array[$loop_index]['FILE'][0]['@']['NAME'])."/<br>";


                }
            }
        }
    }
}
?>